﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SvgToDxfConverter
{
    class FileHelper
    {/// <summary>
     /// 获取带版本号的文件路径（如果原文件已存在）
     /// </summary>
     /// <param name="directory">目标目录</param>
     /// <param name="fileName">原始文件名（带后缀）</param>
     /// <returns>唯一的新文件路径</returns>
        public static string GetUniqueFileName(string directory, string fileName)
        {
            // 分离文件名和后缀
            string fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileName);
            string extension = Path.GetExtension(fileName);

            string newFileName = fileName;
            int version = 1;

            // 检查文件是否存在，若存在则循环增加版本号
            while (File.Exists(Path.Combine(directory, newFileName)))
            {
                newFileName = $"{fileNameWithoutExt} ({version}){extension}";
                version++;
            }

            return Path.Combine(directory, newFileName);
        }
    }
}
